package com.his.registration.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.his.common.PageBean;
import com.his.registration.mapper.RegisterMapper;
import com.his.registration.pojo.Employee;
import com.his.registration.pojo.Register;
import com.his.registration.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.service
 * @Author: ZhangYing
 * @Date: 2023/7/1 14:53
 * @Description:
 */
@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    private RegisterMapper registerMapper;
    @Override
    public int insert(Register register) {
        return registerMapper.insert(register);
    }

    //获得最后的病历号并加1
    @Override
    public int getCaseNum() {
        int caseNum=Integer.parseInt(registerMapper.getLastCaseNum());
        caseNum++;
        return caseNum;
    }

    @Override
    public List<Register> selectForPatients(String caseNumber, String realName,int visitState) {
        return registerMapper.selectForPatients(caseNumber,realName,visitState);
    }

    @Override
    public int updateVisitState(String caseNumber,int visitState) {
        return registerMapper.updateVisitState(caseNumber,visitState);
    }

    @Override
    public PageBean selectByVisitState(int visitState, int page, int pageSize) {
        //1.设置分页参数
        PageHelper.startPage(page,pageSize);

        //2.执行查询
        List<Register> registerList = registerMapper.selectByVisitState(visitState);
        //分装成Page对象
        Page<Register> p=(Page<Register>) registerList;

        //3.封装PageBean对象
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
//        System.out.println("*************************"+p.getTotal());//13:全全部的行数
//        System.out.println("*************************"+p.getResult());//分页得到的一页数据
        return pageBean;
    }

    @Override
    public Register selectById(int id) {
        return registerMapper.selectById(id);
    }

    @Override
    public int getRegistId(String caseNumber) {
        return registerMapper.getRegistId(caseNumber);
    }

    @Override
    public Register getOne(String caseNumber, String realName) {
        return registerMapper.getOne(caseNumber,realName);
    }
}
